package com.gxuwz.Market.business.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.gxuwz.Market.business.dao.ServiceMajorDAO;
import com.gxuwz.Market.business.entity.ServiceMajor;
import com.gxuwz.core.pagination.Result;

import net.sf.json.JSONObject;

@Service("serviceMajorService")
public class ServiceMajorImpl implements IServiceMajorService {
	
	@Autowired
	private ServiceMajorDAO serviceMajorDAO;

	@Override
	public ServiceMajor findById(int id) {
		// TODO Auto-generated method stub
		return serviceMajorDAO.findById(id);
	}

	@Override
	public List<ServiceMajor> findAll() {
		// TODO Auto-generated method stub
		return serviceMajorDAO.findAll();
	}

	@Override
	public Result<ServiceMajor> find(ServiceMajor serviceMajor, int page, int size) {
		// TODO Auto-generated method stub
		return serviceMajorDAO.find(serviceMajor, page, size);
	}

	@Override
	public List<ServiceMajor> findByProperty(String property, String value) {
		// TODO Auto-generated method stub
		return serviceMajorDAO.findByProperty(property, value);
	}

	@Override
	public void add(ServiceMajor serviceMajor) {
		// TODO Auto-generated method stub
		serviceMajorDAO.save(serviceMajor);

	}

	@Override
	public void delete(int id) {
		// TODO Auto-generated method stub
		ServiceMajor serviceMajor = serviceMajorDAO.findById(id);
		serviceMajorDAO.remove(serviceMajor);

	}

	@Override
	public void update(ServiceMajor serviceMajor) {
		// TODO Auto-generated method stub
		serviceMajorDAO.update(serviceMajor);

	}

	/**
	 * 异步查找专业列表
	 */
	@Override
	public List<ServiceMajor> findAllMajorByAcademy(String JSON) {
		// TODO Auto-generated method stub
		List<ServiceMajor> list = null;
		if(!"".equals(JSON) && null!=JSON){
			JSONObject obj = JSONObject.fromObject(JSON);
			try{
				if(null != obj){
					if(obj.has("academyId")&& !"".equals(obj.getString("academyId"))&& null != obj.getString("academyId")){
						list=serviceMajorDAO.findAllMajorByAcademy(obj.getString("academyId"));
						
					}else{
						list = serviceMajorDAO.findAll();
					}
					
				}
				
			}catch (Exception e) {
				e.printStackTrace();
			}
			
			
		}
		
		return list;
	}

}
